package com.qms.qep.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.qms.common.annotation.Log;
import com.qms.common.core.controller.BaseController;
import com.qms.common.core.domain.AjaxResult;
import com.qms.common.enums.BusinessType;
import com.qms.qep.domain.DeviceCalibration;
import com.qms.qep.service.IDeviceCalibrationService;
import com.qms.common.utils.poi.ExcelUtil;
import com.qms.common.core.page.TableDataInfo;

/**
 * 设备校准记录Controller
 * 
 * @author qep
 */
@RestController
@RequestMapping("/qep/calibration")
public class DeviceCalibrationController extends BaseController
{
    @Autowired
    private IDeviceCalibrationService deviceCalibrationService;

    /**
     * 查询设备校准记录列表
     */
    @PreAuthorize("@ss.hasPermi('qep:calibration:list')")
    @GetMapping("/list")
    public TableDataInfo list(DeviceCalibration deviceCalibration)
    {
        startPage();
        List<DeviceCalibration> list = deviceCalibrationService.selectDeviceCalibrationList(deviceCalibration);
        return getDataTable(list);
    }

    /**
     * 导出设备校准记录列表
     */
    @PreAuthorize("@ss.hasPermi('qep:calibration:export')")
    @Log(title = "设备校准记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DeviceCalibration deviceCalibration)
    {
        List<DeviceCalibration> list = deviceCalibrationService.selectDeviceCalibrationList(deviceCalibration);
        ExcelUtil<DeviceCalibration> util = new ExcelUtil<DeviceCalibration>(DeviceCalibration.class);
        util.exportExcel(response, list, "设备校准记录数据");
    }

    /**
     * 获取设备校准记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('qep:calibration:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(deviceCalibrationService.selectDeviceCalibrationById(id));
    }

    /**
     * 新增设备校准记录
     */
    @PreAuthorize("@ss.hasPermi('qep:calibration:add')")
    @Log(title = "设备校准记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeviceCalibration deviceCalibration)
    {
        return toAjax(deviceCalibrationService.insertDeviceCalibration(deviceCalibration));
    }

    /**
     * 修改设备校准记录
     */
    @PreAuthorize("@ss.hasPermi('qep:calibration:edit')")
    @Log(title = "设备校准记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeviceCalibration deviceCalibration)
    {
        return toAjax(deviceCalibrationService.updateDeviceCalibration(deviceCalibration));
    }

    /**
     * 删除设备校准记录
     */
    @PreAuthorize("@ss.hasPermi('qep:calibration:remove')")
    @Log(title = "设备校准记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(deviceCalibrationService.deleteDeviceCalibrationByIds(ids));
    }
    
    /**
     * 根据设备ID查询校准记录列表
     */
    @PreAuthorize("@ss.hasPermi('qep:calibration:list')")
    @GetMapping("/listByEquipment/{equipmentId}")
    public AjaxResult listByEquipment(@PathVariable("equipmentId") Long equipmentId)
    {
        DeviceCalibration deviceCalibration = new DeviceCalibration();
        deviceCalibration.setEquipmentId(equipmentId);
        List<DeviceCalibration> list = deviceCalibrationService.selectDeviceCalibrationList(deviceCalibration);
        return success(list);
    }
} 